﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using PPAP.BO;

namespace PPAP.Web.Part
{
    public partial class Report : PageBase
    {
        PPARBO bo = new PPARBO();
        SamplecardBO sbo = new SamplecardBO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["RID"] != null)
                {
                    DataSet ds = bo.GetReportByPPARid(Request.QueryString["RID"].ToString());
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        DataRow dr = ds.Tables[0].Rows[0];
                        lblAddress.Text = dr["address"].ToString();
                        lblTelephone.Text = dr["contacttel"].ToString();
                        lblSupplierNo.Text = dr["suppliercode"].ToString();
                        lblStatus.Text = dr["bdntrevisionstatus"].ToString();
                        txtDecision.Text += dr["decisiontext"].ToString();
                       // txtExplanation.Text += dr["explanations"].ToString();
                        lblDate.Text =dr["endtime"].ToString()==""?"": DateTime.Parse(dr["endtime"].ToString()).ToString("yyyy-MM-dd");
                        lblPerson.Text = dr["quanlityengineer"].ToString();
                        lblFax.Text = dr["contacttel"].ToString();
                        lblCode.Text = dr["postalcode"].ToString();
                        lblDepartment.Text = dr["department"].ToString();
                        lblTestReport.Text = dr["samplingreportno"].ToString();
                        lblPPARNO.Text = dr["pparno"].ToString();
                       // txtExplanation.Text = dr["explanations"].ToString() == "" ? "Explanation:" + dr["remarks"].ToString() : "Explanation:" + dr["explanations"].ToString();
                        lblQM.Text = dr["quanlitymanager"].ToString();
                        //lblQVP.Text = dr["quanlityvp"].ToString();
                        imgvp.ImageUrl = "~/Part/image/"+dr["quanlityvp"].ToString()+".png";

                        DataSet ds2 = sbo.GetList(" s.pparid=" + Request.QueryString["rid"].ToString() + " ");
                        foreach (DataRow drr in ds2.Tables[0].Rows)
                        {
                            if (drr["RESULT"].ToString() == "Y" || drr["RESULT"].ToString() == "R")
                            {
                                txtExplanation.Text += "\n"+drr["testitemname"].ToString() + "\n" + drr["testitemname"].ToString() + " is not available for BDNT. Reason for deviation is " + drr["reason"].ToString() + "\n\n";
                            }
                        }

                        if (dr["finalresult"].ToString() == "G")
                        {
                            txtDecision.Text = "Successfully released ";
                        }
                        if (dr["finalresult"].ToString() == "Y")
                        {
                            txtDecision.Text = "The final result is conditionally released , the reason  is " + dr["reasondisapprovalbybp"].ToString();
                        }
                        if (dr["finalresult"].ToString() == "R")
                        {
                            txtDecision.Text = "We expect a new PPAR-Report as well as samples by the re-submission date " + (dr["resubmissiondate"].ToString() == "" ? "" : DateTime.Parse(dr["resubmissiondate"].ToString()).ToString("yyyy-MM-dd")) + ". ";
                        }
                    }
                }
            }
        }
    }
}